class Solution {
public:
    string longestCommonPrefix(vector<string>& strs) {
        string ret = strs[0];
        for(int i = 1; i < strs.size(); ++i)
        {
            ret = TowlongestCommonPrefix(ret, strs[i]);
        }
        return ret;
    }
 
    string TowlongestCommonPrefix(string& str1, string& str2)
    {
        if(str1.size() > str2.size())
            swap(str1, str2);
 
        for(int i = 0; i < str1.size(); ++i)
        {
            if(str1[i] == str2[i])
                continue;
            else
                return str1.substr(0, i);
        }
        return str1;
    }
};